package ch.ifage.ws.rest;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import ch.ifage.business.dom.Step;
import ch.ifage.business.service.WorkflowsServiceImplMock;


/**
 * 
 * @author Christian
 *
 */
@Path("/")
public class WorkFlowInfoImpl implements WorkFlowInfo {

	/**
	 * Stocks les WF.
	 */
	@Inject
	private WorkflowsServiceImplMock wfsService = new WorkflowsServiceImplMock();

	/**
	 * URL : 
	 * @param string to find in the logs.
	 * @return the step that contains the string or null.
	 */
	@GET
	@Path("getStepLogContains") 
	@Produces ({MediaType.TEXT_PLAIN})
	public String getStepLogContains(@QueryParam("string") String string) {
		if (string.length() <= 3) {
			return "String to find must be greater than 3 chars.";
		}
		//wfsService  = new WorkflowsServiceImplMock();
		System.out.println("getStepLogContains");
		Step stepFound = wfsService.getWfsService().getStepLogContains(string);
		if ( stepFound == null) {
			return "No step found";
		}
		else {
			return stepFound.getProperties().getLog();
		}
	}
	
	/**
	 * Test URL: http://localhost:8080/AnalyseFluxRestServer/hello
	 * @return hello 
	 */
	@GET
	@Path("hello") 
	@Produces ({MediaType.TEXT_PLAIN})
	public String hello() {
		return "Hello!";
	}

}
